package hhm.utils.client;

import java.io.IOException;

import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class testLogin {
	public static void main(String[] args) {

		CloseableHttpClient httpClient = HttpClients.createDefault();

		CredentialsProvider credsProvider = new BasicCredentialsProvider();
		credsProvider.setCredentials(new AuthScope("192.168.10.29", 80), new UsernamePasswordCredentials("admin", ""));

		HttpHost target = new HttpHost("192.168.10.29", 80, "http");
		HttpClientContext context = HttpClientContext.create();
		context.setCredentialsProvider(credsProvider);

		HttpGet httpPost = new HttpGet("/");

		HttpResponse response = null;
		try {
			response = httpClient.execute(target, httpPost, context);
			String result = EntityUtils.toString(response.getEntity());

			System.out.println(result);
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
